package com.ywj.activemq.service.impl;

import com.ywj.activemq.service.MessageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;

@Service
public class MessageServiceImpl implements MessageService {
    protected static final Logger logger = LoggerFactory.getLogger(MessageServiceImpl.class);
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Override
    public void sendMessage(String message) {
        logger.info("=============MessageServiceImpl中的sendmessage============");
        System.out.println("等待发送的信息为：" + message);
        jmsMessagingTemplate.convertAndSend("order.queue.message",message);
    }

    @Override
    public String doMessage() {
        logger.info("=============MessageServiceImpl中的domessage============");
        String message = jmsMessagingTemplate.receiveAndConvert("order.queue.message",String.class);
        System.out.println("已经接收到信息：" + message);
        return message;
    }
}

